cls
clear all
global filepath = "G:/****/****/****/****/analysis/cyriackodath/OBES_Paper"   
cd "$filepath"
capture log close
log using IWP_OBES_Results.txt, text replace
use IWP_Dataset, clear


*** Generate Summary Statistics - Table 1
bysort nino: keep if _n == 1
tab gender treatment , column
tab regions treatment, column
tab treatment age_cat, column
tab has_partner treatment , column
tab has_partner_ontrial treatment , column


* Reload Original Dataset
use IWP_Dataset, clear

*** Single Balancing Tests - Table 2(a)
local baseline_vars1 "age gender fullservice liveservice partner partnerontrial north_east wales north_west lhc scotland southern central"
local comparisons "treatment1_23 treatment1_2 treatment1_3 treatment2_3"
foreach var of local baseline_vars1 {
	foreach comp of local comparisons {
		reg `comp' `var' if weeknumber == 1, robust       
}
}

*** Joint Balancing Tests - Table 2(b)
local baseline_vars2 "age gender liveservice partner partnerontrial north_east north_west lhc scotland southern central"
local comparisons "treatment1_23 treatment1_2 treatment1_3 treatment2_3"
foreach comp of local comparisons {
reg `comp' `baseline_vars2' if weeknumber == 1, robust       
}


** Generate Mutually Exclusive Time Dummies (t,c,d,e,f,g,h)
drop if weeknumber >130
gen t = 0 if weeknumber < 53
replace t = 1 if weeknumber > 52

gen c = 0 if weeknumber < 53
replace c = 1 if weeknumber > 52
replace c = 0 if weeknumber > 65

gen d = 0 if weeknumber < 53
replace d = 0 if weeknumber > 52
replace d = 1 if weeknumber > 65 
replace d = 0 if weeknumber > 78

gen e = 0 if weeknumber < 53
replace e = 0 if weeknumber > 52
replace e = 1 if weeknumber > 78 
replace e = 0 if weeknumber > 91

gen f = 0 if weeknumber < 53
replace f = 0 if weeknumber > 52
replace f = 1 if weeknumber > 91 
replace f = 0 if weeknumber > 104

gen g = 0 if weeknumber < 53
replace g = 0 if weeknumber > 52
replace g = 1 if weeknumber > 104 
replace g = 0 if weeknumber > 117

gen h = 0 if weeknumber < 53
replace h = 0 if weeknumber > 52
replace h = 1 if weeknumber > 117
replace h = 0 if weeknumber > 130

** Generate Mutually Exclusive Time Dummies for PreTreatment Period (w,x,y,z)
gen w = 1 if weeknumber > 0
replace w = 0 if weeknumber > 13

gen x = 1 if weeknumber > 0
replace x = 0 if weeknumber > 26
replace x = 0 if weeknumber < 14

gen y = 1 if weeknumber > 0
replace y = 0 if weeknumber > 39
replace y = 0 if weeknumber < 27

gen z = 1 if weeknumber > 0
replace z = 0 if weeknumber > 52
replace z = 0 if weeknumber < 40


** Generating interaction terms for Difference in Difference Regression - Mutually Exclusive Time Periods (t,c,d,e,f,g,h)
gen did2 = t*treatment2
gen did3 = t*treatment3
gen did2c = c*treatment2
gen did3c = c*treatment3
gen did2d = d*treatment2
gen did3d = d*treatment3
gen did2e = e*treatment2
gen did3e = e*treatment3
gen did2f = f*treatment2
gen did3f = f*treatment3
gen did2g = g*treatment2
gen did3g = g*treatment3
gen did2h = h*treatment2
gen did3h = h*treatment3

** Generating interaction terms for Difference in Difference Regression - Mutually Exclusive Time Periods - Pre Treatment Period (w,x,y,z)
gen did2w = w*treatment2
gen did3w = w*treatment3
gen did2x = x*treatment2
gen did3x = x*treatment3
gen did2y = y*treatment2
gen did3y = y*treatment3
gen did2z = z*treatment2
gen did3z = z*treatment3


*** Appendix A - Table A1 - Moderate + Frequent - Coloumns 1 & 2
reg weeklypay treatment2 w x z c d e f g h did2w did2x did2z did2c did2d did2e did2f did2g did2h if treatment1==1 | treatment2==1, vce(cluster nino)
testparm did2w did2x did2z

reg weeklypay treatment3 w x z c d e f g h did3w did3x did3z did3c did3d did3e did3f did3g did3h if treatment1==1 | treatment3==1, vce(cluster nino)
testparm did3w did3x did3z

*** Appendix A - Table A1 - Moderate + Frequent - Male vs Female - Coloumns 3,4,5,6
reg weeklypay treatment2 w x z c d e f g h did2w did2x did2z did2c did2d did2e did2f did2g did2h if male==1 & (treatment1==1 | treatment2==1), vce(cluster nino)
testparm did2w did2x did2z
reg weeklypay treatment2 w x z c d e f g h did2w did2x did2z did2c did2d did2e did2f did2g did2h if female==1 & (treatment1==1 | treatment2==1), vce(cluster nino)
testparm did2w did2x did2z

reg weeklypay treatment3 w x z c d e f g h did3w did3x did3z did3c did3d did3e did3f did3g did3h if male==1 & (treatment1==1 | treatment3==1), vce(cluster nino)
testparm did3w did3x did3z
reg weeklypay treatment3 w x z c d e f g h did3w did3x did3z did3c did3d did3e did3f did3g did3h if female==1 & (treatment1==1 | treatment3==1), vce(cluster nino)
testparm did3w did3x did3z


*** Appendix A - Table A1 (Mean Estimate) Moderate + Frequent - Coloumns 1 & 2
reg weeklypay t treatment2 did2 if treatment1==1 | treatment2==1
reg weeklypay t treatment3 did3 if treatment1==1 | treatment3==1
*** Appendix A - Table A1 (Mean Estimate) Moderate + Frequent - Male vs Female - Coloumns 3,4,5,6
reg weeklypay t treatment2 did2 if male == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if female == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment3 did3 if male == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if female == 1 & (treatment1==1 | treatment3==1)
*** Appendix A - Table A1 (Pre-Treatment Tests) Moderate + Frequent - Coloumns 1 & 2
gen age2 = age*age
local controls "age age2 gender partner partnerontrial north_east wales north_west lhc scotland southern"
regress weeklypay week_dummy1-week_dummy130 int1_23_week1-int1_23_week130 `controls' if treatment1_2 ~=., noc cluster(nino)
est store t2vs1
testparm int1_23_week1-int1_23_week52
local controls "age age2 gender partner partnerontrial north_east wales north_west lhc scotland southern"
regress weeklypay week_dummy1-week_dummy130 int1_23_week1-int1_23_week130 `controls' if treatment1_3 ~=., noc cluster(nino)
est store t3vs1 
testparm int1_23_week1-int1_23_week52
*** Appendix A - Table A1 (Pre-Treatment Tests) Moderate + Frequent - Male vs Female - Coloumns 3,4,5,6
foreach x in 0 1 {
	regress weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130 if male ==`x', noc cluster(nino)
	testparm int1_2_week1-int1_2_week52
	regress weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130 if male ==`x', noc cluster(nino)
	testparm int1_3_week1-int1_3_week52
}


*** Appendix A - Table A2(a)- Age Categories - Average Treatment Effects - Moderate 
reg weeklypay t treatment2 did2 if age_cat == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if age_cat == 2 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if age_cat == 3 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if age_cat == 4 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if age_cat == 5 & (treatment1==1 | treatment2==1)
*** Appendix A - Table A2(a) - Age Categories - Moderate (Pre Treatement Test)
foreach x in 1 2 3 4 5 {
	regress weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130 if age_cat ==`x', noc cluster(nino)
	testparm int1_2_week1-int1_2_week52
}
*** Appendix A - Table A2(b) - Age Categories - Average Treatment Effects - Frequent
reg weeklypay t treatment3 did3 if age_cat == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if age_cat == 2 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if age_cat == 3 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if age_cat == 4 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if age_cat == 5 & (treatment1==1 | treatment3==1)
*** Appendix A - Table A2(b) - Age Categories - Frequent (Pre Treatement Test)
foreach x in 1 2 3 4 5 {
	regress weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130 if age_cat ==`x', noc cluster(nino)
	testparm int1_3_week1-int1_3_week52
}


*** Appendix A - Table A3(a)- Regions - Average Treatment Effects - Moderate 
reg weeklypay t treatment2 did2 if wales == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if north_west == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if southern == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if north_east == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if scotland == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if lhc == 1 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if central == 1 & (treatment1==1 | treatment2==1)
*** Appendix A - Table A3(a) - Regions - Moderate (Pre Treatement Test)
foreach x in wales north_west southern north_east scotland lhc central {
	regress weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130 if `x'==1, noc cluster(nino)
	testparm int1_2_week1-int1_2_week52
}
*** Appendix A - Table A3(b) - Regions - Average Treatment Effects - Frequent
reg weeklypay t treatment3 did3 if wales == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if north_west == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if southern == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if north_east == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if scotland == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if lhc == 1 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if central == 1 & (treatment1==1 | treatment3==1)
*** Appendix A - Table A3(b) - Regions - Frequent (Pre Treatement Test)
foreach x in wales north_west southern north_east scotland lhc central {
	regress weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130 if `x'==1, noc cluster(nino)
	testparm int1_3_week1-int1_3_week52
}


*** Appendix B - Table B1 - Quantile Estimates - Moderate + Frequent - Coloumns 1 & 2
set seed 1001
sqreg weeklypay t treatment2 did2 if treatment1==1 | treatment2==1, q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment3 did3 if treatment1==1 | treatment3==1, q(.4 .5 .6 .7 .8 .9)
*** Appendix B - Table B1 - Quantile Estimates - Moderate (Male vs Female) - Coloumns 3 & 4
sqreg weeklypay t treatment2 did2 if male==1 & (treatment1==1 | treatment2==1), q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment2 did2 if female==1 & (treatment1==1 | treatment2==1), q(.4 .5 .6 .7 .8 .9)
*** Appendix B - Table B1 - Quantile Estimates - Frequent (Male vs Female) - Coloumns 5 & 6
sqreg weeklypay t treatment3 did3 if male==1 & (treatment1==1 | treatment3==1), q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment3 did3 if female==1 & (treatment1==1 | treatment3==1), q(.4 .5 .6 .7 .8 .9)


*** Appendix B - Table B2 - Quantile Rergressions - Moderate - Test for Parallel Pre-Treatment Trends
qreg weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130, quantile(0.5)
testparm int1_2_week1-int1_2_week52
qreg weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130, quantile(0.6)
testparm int1_2_week1-int1_2_week52
qreg weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130, quantile(0.7)
testparm int1_2_week1-int1_2_week52
qreg weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130, quantile(0.8)
testparm int1_2_week1-int1_2_week52
qreg weeklypay treatment1_2 week_dummy1-week_dummy130 int1_2_week1-int1_2_week52 int1_2_week54-int1_2_week130, quantile(0.9)
testparm int1_2_week1-int1_2_week52
*** Appendix B - Table B2 - Quantile Rergressions - Frequent - Test for Parallel Pre-Treatment Trends
qreg weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130, quantile(0.5)
testparm int1_3_week1-int1_3_week52
qreg weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130, quantile(0.6)
testparm int1_3_week1-int1_3_week52
qreg weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130, quantile(0.7)
testparm int1_3_week1-int1_3_week52
qreg weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130, quantile(0.8)
testparm int1_3_week1-int1_3_week52
qreg weeklypay treatment1_3 week_dummy1-week_dummy130 int1_3_week1-int1_3_week52 int1_3_week54-int1_3_week130, quantile(0.9)
testparm int1_3_week1-int1_3_week52


*** Appendix C - Table C1 - Quantile Estimates - Women by Age
set seed 1001
sqreg weeklypay t treatment2 did2 if female==1 & age>35 & (treatment1==1 | treatment2==1), q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment2 did2 if female==1 & age<36 & (treatment1==1 | treatment2==1), q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment3 did3 if female==1 & age>35 & (treatment1==1 | treatment3==1), q(.4 .5 .6 .7 .8 .9)
sqreg weeklypay t treatment3 did3 if female==1 & age<36 & (treatment1==1 | treatment3==1), q(.4 .5 .6 .7 .8 .9)
*** Appendix C - Table C1 - Mean Estimate - Women by Age
reg weeklypay t treatment2 did2 if female==1 & age>35 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment2 did2 if female==1 & age<36 & (treatment1==1 | treatment2==1)
reg weeklypay t treatment3 did3 if female==1 & age>35 & (treatment1==1 | treatment3==1)
reg weeklypay t treatment3 did3 if female==1 & age<36 & (treatment1==1 | treatment3==1)


// Generating year dummies to evaluate calendar effects by year of trial start
gen year = substr(pstart, 6, .)
gen year2 = real(year)
gen year15 = 0
replace year15 = 1 if year2 == 2015
gen year16 = 0
replace year16 = 1 if year2 == 2016
gen year17 = 0
replace year17 = 1 if year2 == 2017

*** APPENDIX D - Robustness - Table D1 - Year of Entry (2016 + 2017)
reg weeklypay t treatment2 did2 if year16==1 & (treatment1==1 | treatment2==1), vce(cluster nino)
reg weeklypay t treatment2 did2 if year17==1 & (treatment1==1 | treatment2==1), vce(cluster nino)
reg weeklypay t treatment3 did3 if year16==1 & (treatment1==1 | treatment3==1), vce(cluster nino)
reg weeklypay t treatment3 did3 if year17==1 & (treatment1==1 | treatment3==1), vce(cluster nino)

// Generate Interaction Terms for 2017*Time*Treatment
gen did2t = year17*t*treatment2
gen did3t = year17*t*treatment3
gen t_17 = year17*t
gen treatment2_17 = year17*treatment2
gen treatment3_17 = year17*treatment3
drop if year15==1

*** APPENDIX D - Robustness - Table D1 - Difference in Effect (2017 vs 2016)
reg weeklypay t treatment2 did2 year17 t_17 treatment2_17 did2t if treatment1==1 | treatment2==1, vce(cluster nino)
reg weeklypay t treatment3 did3 year17 t_17 treatment3_17 did3t if treatment1==1 | treatment3==1, vce(cluster nino)


*** Reload Dataset and generate Time Dummies
use IWP_Dataset, clear
** Generate Mutually Exclusive Time Dummies (t,c,d,e,f,g,h)
drop if weeknumber >130
gen t = 0 if weeknumber < 53
replace t = 1 if weeknumber > 52

gen c = 0 if weeknumber < 53
replace c = 1 if weeknumber > 52
replace c = 0 if weeknumber > 65

gen d = 0 if weeknumber < 53
replace d = 0 if weeknumber > 52
replace d = 1 if weeknumber > 65 
replace d = 0 if weeknumber > 78

gen e = 0 if weeknumber < 53
replace e = 0 if weeknumber > 52
replace e = 1 if weeknumber > 78 
replace e = 0 if weeknumber > 91

gen f = 0 if weeknumber < 53
replace f = 0 if weeknumber > 52
replace f = 1 if weeknumber > 91 
replace f = 0 if weeknumber > 104

gen g = 0 if weeknumber < 53
replace g = 0 if weeknumber > 52
replace g = 1 if weeknumber > 104 
replace g = 0 if weeknumber > 117

gen h = 0 if weeknumber < 53
replace h = 0 if weeknumber > 52
replace h = 1 if weeknumber > 117
replace h = 0 if weeknumber > 130

** Generating interaction terms for Difference in Difference Regression - Mutually Exclusive Time Periods (t,c,d,e,f,g,h)
gen did2 = t*treatment2
gen did3 = t*treatment3
gen did2c = c*treatment2
gen did3c = c*treatment3
gen did2d = d*treatment2
gen did3d = d*treatment3
gen did2e = e*treatment2
gen did3e = e*treatment3
gen did2f = f*treatment2
gen did3f = f*treatment3
gen did2g = g*treatment2
gen did3g = g*treatment3
gen did2h = h*treatment2
gen did3h = h*treatment3

gen age2 = age*age

*** APPENDIX D - Robustness - Table D2 - Alternative Specifications - Moderate Treatment (DiD / Controls / Ancova)
reg weeklypay c d e f g h treatment2 did2c did2d did2e did2f did2g did2h if treatment1==1 | treatment2==1, vce(cluster nino)
est store spec1
reg weeklypay c d e f g h treatment2 did2c did2d did2e did2f did2g did2h age age2 male partner partnerontrial north_east wales north_west lhc scotland southern if treatment1==1 | treatment2==1, vce(cluster nino)
est store spec2
reg weeklypay c d e f g h pre_mean_pay_fill did2c did2d did2e did2f did2g did2h if treatment1==1 | treatment2==1, vce(cluster nino)
est store spec3

*** APPENDIX D - Robustness - Table D2 - Alternative Specifications - Frequent Treatment (DiD / Controls / Ancova)
reg weeklypay c d e f g h treatment3 did3c did3d did3e did3f did3g did3h if treatment1==1 | treatment3==1, vce(cluster nino)
est store spec4
reg weeklypay c d e f g h treatment3 did3c did3d did3e did3f did3g did3h age age2 male partner partnerontrial north_east wales north_west lhc scotland southern if treatment1==1 | treatment3==1, vce(cluster nino)
est store spec5
reg weeklypay c d e f g h pre_mean_pay_fill did3c did3d did3e did3f did3g did3h if treatment1==1 | treatment3==1, vce(cluster nino)
est store spec6


*** APPENDIX E - Non Printing Appendix - Table E1 - Difference in Levels of Weekly Wages 
regress weeklypay week_dummy1-week_dummy130 int1_23_week1-int1_23_week130, noc cluster(nino)
est store t23vs1_nc
testparm int1_23_week1-int1_23_week52

regress weeklypay week_dummy1-week_dummy130 int1_23_week1-int1_23_week130 if treatment1_2 ~=., noc cluster(nino)
est store t2vs1_nc
testparm int1_23_week1-int1_23_week52

regress weeklypay week_dummy1-week_dummy130 int1_23_week1-int1_23_week130 if treatment1_3 ~=., noc cluster(nino)
est store t3vs1_nc
testparm int1_23_week1-int1_23_week52

log close